package com.tianma315.admin.device.controller;


import java.util.Arrays;
import java.util.List;

import com.tianma315.admin.common.base.BaseController;
import com.tianma315.admin.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.device.domain.MaintainTypeDO;
import com.tianma315.admin.device.service.MaintainTypeService;

/**
 * 
 * <pre>
 * 设备维护类型
 * </pre>
 * <small> 2019-05-22 16:08:48 | Aron</small>
 */
@Controller
@RequestMapping("/device/maintainType")
public class MaintainTypeController extends BaseController{
	@Autowired
	private MaintainTypeService maintainTypeService;
	
	@GetMapping()
	@RequiresPermissions("device:maintainType:maintainType")
	String MaintainType(){
	    return "device/maintainType/maintainType";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("device:maintainType:maintainType")
	public Result<Page<MaintainTypeDO>> list(Integer pageNumber, Integer pageSize, MaintainTypeDO maintainTypeDTO){
		// 查询列表数据
        Page<MaintainTypeDO> page = maintainTypeService.getMaintainTypeDOPage(pageNumber,pageSize,maintainTypeDTO);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("device:maintainType:add")
	String add(){
	    return "device/maintainType/add";
	}

	@GetMapping("/edit/{maintainTypeId}")
	@RequiresPermissions("device:maintainType:edit")
	String edit(@PathVariable("maintainTypeId") Integer maintainTypeId,Model model){
		MaintainTypeDO maintainType = maintainTypeService.selectById(maintainTypeId);
		model.addAttribute("maintainType", maintainType);
	    return "device/maintainType/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("device:maintainType:add")
	public Result<String> save( MaintainTypeDO maintainType){
		if(maintainTypeService.addMaintainTypeDO(maintainType)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("device:maintainType:edit")
	public Result<String>  update( MaintainTypeDO maintainType){
		maintainTypeService.updateById(maintainType);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("device:maintainType:remove")
	public Result<String>  remove( Integer maintainTypeId){
		if(maintainTypeService.deleteMaintainTypeDO(maintainTypeId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("device:maintainType:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] maintainTypeIds){
		for (int i = 0; i < maintainTypeIds.length; i++) {
			maintainTypeService.deleteMaintainTypeDO(maintainTypeIds[i]);
		}
		return Result.ok();
	}

	/**
	 * 下拉数据
	 */
	@GetMapping( "/getMaintainTypeList")
	@ResponseBody
	public Result<List<MaintainTypeDO>>  getMaintainTypeList(){
		List<MaintainTypeDO> maintainTypeDOS = maintainTypeService.getMaintainTypeDOList();
		return Result.ok(maintainTypeDOS);
	}
	
}
